package pkg

import (
	"time"
)

func GetFirstDateOfWeek() time.Time {
	now := time.Now()

	offset := int(time.Monday - now.Weekday())
	if offset > 0 {
		offset = -6
	}

	return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
}

func GetLastDateOfWeek() time.Time {
	now := time.Now()

	offset := int(time.Saturday - now.Weekday())
	if offset == 6 {
		offset = -1
	}

	return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset+1)
}

func GetFirstDateOfMonth() time.Time {
	d := time.Now()
	return d.AddDate(0, 0, -d.Day()+1)
}

func GetLastDateOfMonth() time.Time {
	return GetFirstDateOfMonth().AddDate(0, 1, -1)
}

func GetFirstDateOfYear() time.Time {
	now := time.Now()
	currentYear, _, _ := now.Date()
	currentLocation := now.Location()
	return time.Date(currentYear, time.January, 1, 0, 0, 0, 0, currentLocation)
}

func GetLastDateOfYear() time.Time {
	now := time.Now()
	currentYear, currentMonth, _ := now.Date()
	currentLocation := now.Location()
	return time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation).AddDate(1, 0, -1)
}
